package Servlet;

import Utility.Utility;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/update")
public class Update extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();

        String id =req.getParameter("id");
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String sex = req.getParameter("sex");
        String address = req.getParameter("address");

        System.out.println(id+","+name+","+age+","+sex+","+address);

        String sql = "update student set name=?,age=?,sex=?,address=? where id=?";
        int i = Utility.delete(sql,name,age,sex,address,id);
        if(i>0){
            out.write("修改成功！");
        }else{
            out.write("修改失败！");
        }
        out.write("<a href=\"http://localhost:8080/stu\">返回</a>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
